package com.qimu.saiyou.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: FeiXiang
 * @Date: 2023年05月25日 15:42
 * @Version: 1.0
 * @Description:
 */
@Configuration
public class DelayExchangeConfig {
    public static final String DEADLINE_DELAY_QUEUE = "deadline.delay.queue";
    public static final String DEADLINE_DELAY_EXCHANGE = "deadline.delay.exchange";
    public static final String DEADLINE_DELAY_ROUTING_KEY = "deadline.delay.routingKey";

    public static final String END_DELAY_QUEUE = "end.delay.queue";
    public static final String END_DELAY_EXCHANGE = "end.delay.exchange";
    public static final String END_DELAY_ROUTING_KEY = "end.delay.routingKey";

    public static final String END_DELAY_USER_PAPER_QUEUE = "end.delay.user.paper.queue";
    public static final String END_DELAY_USER_PAPER_EXCHANGE = "end.delay.user.paper.exchange";
    public static final String END_DELAY_USER_PAPER_ROUTING_KEY = "end.delay.user.paper.routingKey";
    @Bean
    public CustomExchange deadlineDaylyExchange() {
        Map<String, Object> arguments = new HashMap<>(1);
        arguments.put("x-delayed-type", "direct");
        return new CustomExchange(DEADLINE_DELAY_EXCHANGE, "x-delayed-message", true, false, arguments);
    }

    @Bean
    public Queue deadlineDdaylyQueue() {
        return new Queue(DEADLINE_DELAY_QUEUE);
    }

    @Bean
    public Binding deadlinebindingDelay(@Qualifier("deadlineDaylyExchange") CustomExchange customExchange, @Qualifier("deadlineDdaylyQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(customExchange).with(DEADLINE_DELAY_ROUTING_KEY).noargs();
    }


    @Bean
    public CustomExchange endDaylyExchange() {
        Map<String, Object> arguments = new HashMap<>(1);
        arguments.put("x-delayed-type", "direct");
        return new CustomExchange(END_DELAY_EXCHANGE, "x-delayed-message", true, false, arguments);
    }

    @Bean
    public Queue endDdaylyQueue() {
        return new Queue(END_DELAY_QUEUE);
    }

    @Bean
    public Binding endbindingDelay(@Qualifier("endDaylyExchange") CustomExchange customExchange, @Qualifier("endDdaylyQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(customExchange).with(END_DELAY_ROUTING_KEY).noargs();
    }


    @Bean
    public CustomExchange userDaylyExchange() {
        Map<String, Object> arguments = new HashMap<>(1);
        arguments.put("x-delayed-type", "direct");
        return new CustomExchange(END_DELAY_USER_PAPER_EXCHANGE, "x-delayed-message", true, false, arguments);
    }

    @Bean
    public Queue userDdaylyQueue() {
        return new Queue(END_DELAY_USER_PAPER_QUEUE);
    }

    @Bean
    public Binding userbindingDelay(@Qualifier("userDaylyExchange") CustomExchange customExchange, @Qualifier("userDdaylyQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(customExchange).with(END_DELAY_USER_PAPER_ROUTING_KEY).noargs();
    }
}
